﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace becom.DAL
{
	/// <summary>
	/// 数据访问类:oa_material_definition
	/// </summary>
	public partial class oa_material_definition
	{
		public oa_material_definition()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperMySQL.GetMaxID("ID", "oa_material_definition"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from oa_material_definition");
			strSql.Append(" where ID=@ID");
			MySqlParameter[] parameters = {
					new MySqlParameter("@ID", MySqlDbType.Int32)
};
			parameters[0].Value = ID;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(becom.Model.oa_material_definition model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into oa_material_definition(");
			strSql.Append("MaterialTheme,MaterialExplain,MaterialRemark,MaterialDefDate,MaterialValidStar,MaterialValidEnd,ReceiverPeoplNum,MaterialStatus,AlreadySubmitNum,FieldNum,CreatePeopleCode,CreateDate)");
			strSql.Append(" values (");
			strSql.Append("@MaterialTheme,@MaterialExplain,@MaterialRemark,@MaterialDefDate,@MaterialValidStar,@MaterialValidEnd,@ReceiverPeoplNum,@MaterialStatus,@AlreadySubmitNum,@FieldNum,@CreatePeopleCode,@CreateDate)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@MaterialTheme", MySqlDbType.VarChar,20),
					new MySqlParameter("@MaterialExplain", MySqlDbType.VarChar,100),
					new MySqlParameter("@MaterialRemark", MySqlDbType.VarChar,200),
					new MySqlParameter("@MaterialDefDate", MySqlDbType.DateTime),
					new MySqlParameter("@MaterialValidStar", MySqlDbType.DateTime),
					new MySqlParameter("@MaterialValidEnd", MySqlDbType.DateTime),
					new MySqlParameter("@ReceiverPeoplNum", MySqlDbType.Int32,11),
					new MySqlParameter("@MaterialStatus", MySqlDbType.Int32,11),
					new MySqlParameter("@AlreadySubmitNum", MySqlDbType.Int32,11),
					new MySqlParameter("@FieldNum", MySqlDbType.Int32,11),
					new MySqlParameter("@CreatePeopleCode", MySqlDbType.VarChar,10),
					new MySqlParameter("@CreateDate", MySqlDbType.DateTime)};
			parameters[0].Value = model.MaterialTheme;
			parameters[1].Value = model.MaterialExplain;
			parameters[2].Value = model.MaterialRemark;
			parameters[3].Value = model.MaterialDefDate;
			parameters[4].Value = model.MaterialValidStar;
			parameters[5].Value = model.MaterialValidEnd;
			parameters[6].Value = model.ReceiverPeoplNum;
			parameters[7].Value = model.MaterialStatus;
			parameters[8].Value = model.AlreadySubmitNum;
			parameters[9].Value = model.FieldNum;
			parameters[10].Value = model.CreatePeopleCode;
			parameters[11].Value = model.CreateDate;

			DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(becom.Model.oa_material_definition model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update oa_material_definition set ");
			strSql.Append("MaterialTheme=@MaterialTheme,");
			strSql.Append("MaterialExplain=@MaterialExplain,");
			strSql.Append("MaterialRemark=@MaterialRemark,");
			strSql.Append("MaterialDefDate=@MaterialDefDate,");
			strSql.Append("MaterialValidStar=@MaterialValidStar,");
			strSql.Append("MaterialValidEnd=@MaterialValidEnd,");
			strSql.Append("ReceiverPeoplNum=@ReceiverPeoplNum,");
			strSql.Append("MaterialStatus=@MaterialStatus,");
			strSql.Append("AlreadySubmitNum=@AlreadySubmitNum,");
			strSql.Append("FieldNum=@FieldNum,");
			strSql.Append("CreatePeopleCode=@CreatePeopleCode,");
			strSql.Append("CreateDate=@CreateDate");
			strSql.Append(" where ID=@ID");
			MySqlParameter[] parameters = {
					new MySqlParameter("@MaterialTheme", MySqlDbType.VarChar,20),
					new MySqlParameter("@MaterialExplain", MySqlDbType.VarChar,100),
					new MySqlParameter("@MaterialRemark", MySqlDbType.VarChar,200),
					new MySqlParameter("@MaterialDefDate", MySqlDbType.DateTime),
					new MySqlParameter("@MaterialValidStar", MySqlDbType.DateTime),
					new MySqlParameter("@MaterialValidEnd", MySqlDbType.DateTime),
					new MySqlParameter("@ReceiverPeoplNum", MySqlDbType.Int32,11),
					new MySqlParameter("@MaterialStatus", MySqlDbType.Int32,11),
					new MySqlParameter("@AlreadySubmitNum", MySqlDbType.Int32,11),
					new MySqlParameter("@FieldNum", MySqlDbType.Int32,11),
					new MySqlParameter("@CreatePeopleCode", MySqlDbType.VarChar,10),
					new MySqlParameter("@CreateDate", MySqlDbType.DateTime),
					new MySqlParameter("@ID", MySqlDbType.Int32,11)};
			parameters[0].Value = model.MaterialTheme;
			parameters[1].Value = model.MaterialExplain;
			parameters[2].Value = model.MaterialRemark;
			parameters[3].Value = model.MaterialDefDate;
			parameters[4].Value = model.MaterialValidStar;
			parameters[5].Value = model.MaterialValidEnd;
			parameters[6].Value = model.ReceiverPeoplNum;
			parameters[7].Value = model.MaterialStatus;
			parameters[8].Value = model.AlreadySubmitNum;
			parameters[9].Value = model.FieldNum;
			parameters[10].Value = model.CreatePeopleCode;
			parameters[11].Value = model.CreateDate;
			parameters[12].Value = model.ID;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_material_definition ");
			strSql.Append(" where ID=@ID");
			MySqlParameter[] parameters = {
					new MySqlParameter("@ID", MySqlDbType.Int32)
};
			parameters[0].Value = ID;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_material_definition ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public becom.Model.oa_material_definition GetModel(int ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,MaterialTheme,MaterialExplain,MaterialRemark,MaterialDefDate,MaterialValidStar,MaterialValidEnd,ReceiverPeoplNum,MaterialStatus,AlreadySubmitNum,FieldNum,CreatePeopleCode,CreateDate from oa_material_definition ");
			strSql.Append(" where ID=@ID");
			MySqlParameter[] parameters = {
					new MySqlParameter("@ID", MySqlDbType.Int32)
};
			parameters[0].Value = ID;

			becom.Model.oa_material_definition model=new becom.Model.oa_material_definition();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					model.ID=int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["MaterialTheme"]!=null && ds.Tables[0].Rows[0]["MaterialTheme"].ToString()!="")
				{
					model.MaterialTheme=ds.Tables[0].Rows[0]["MaterialTheme"].ToString();
				}
				if(ds.Tables[0].Rows[0]["MaterialExplain"]!=null && ds.Tables[0].Rows[0]["MaterialExplain"].ToString()!="")
				{
					model.MaterialExplain=ds.Tables[0].Rows[0]["MaterialExplain"].ToString();
				}
				if(ds.Tables[0].Rows[0]["MaterialRemark"]!=null && ds.Tables[0].Rows[0]["MaterialRemark"].ToString()!="")
				{
					model.MaterialRemark=ds.Tables[0].Rows[0]["MaterialRemark"].ToString();
				}
				if(ds.Tables[0].Rows[0]["MaterialDefDate"]!=null && ds.Tables[0].Rows[0]["MaterialDefDate"].ToString()!="")
				{
					model.MaterialDefDate=DateTime.Parse(ds.Tables[0].Rows[0]["MaterialDefDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["MaterialValidStar"]!=null && ds.Tables[0].Rows[0]["MaterialValidStar"].ToString()!="")
				{
					model.MaterialValidStar=DateTime.Parse(ds.Tables[0].Rows[0]["MaterialValidStar"].ToString());
				}
				if(ds.Tables[0].Rows[0]["MaterialValidEnd"]!=null && ds.Tables[0].Rows[0]["MaterialValidEnd"].ToString()!="")
				{
					model.MaterialValidEnd=DateTime.Parse(ds.Tables[0].Rows[0]["MaterialValidEnd"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ReceiverPeoplNum"]!=null && ds.Tables[0].Rows[0]["ReceiverPeoplNum"].ToString()!="")
				{
					model.ReceiverPeoplNum=int.Parse(ds.Tables[0].Rows[0]["ReceiverPeoplNum"].ToString());
				}
				if(ds.Tables[0].Rows[0]["MaterialStatus"]!=null && ds.Tables[0].Rows[0]["MaterialStatus"].ToString()!="")
				{
					model.MaterialStatus=int.Parse(ds.Tables[0].Rows[0]["MaterialStatus"].ToString());
				}
				if(ds.Tables[0].Rows[0]["AlreadySubmitNum"]!=null && ds.Tables[0].Rows[0]["AlreadySubmitNum"].ToString()!="")
				{
					model.AlreadySubmitNum=int.Parse(ds.Tables[0].Rows[0]["AlreadySubmitNum"].ToString());
				}
				if(ds.Tables[0].Rows[0]["FieldNum"]!=null && ds.Tables[0].Rows[0]["FieldNum"].ToString()!="")
				{
					model.FieldNum=int.Parse(ds.Tables[0].Rows[0]["FieldNum"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CreatePeopleCode"]!=null && ds.Tables[0].Rows[0]["CreatePeopleCode"].ToString()!="")
				{
					model.CreatePeopleCode=ds.Tables[0].Rows[0]["CreatePeopleCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CreateDate"]!=null && ds.Tables[0].Rows[0]["CreateDate"].ToString()!="")
				{
					model.CreateDate=DateTime.Parse(ds.Tables[0].Rows[0]["CreateDate"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,MaterialTheme,MaterialExplain,MaterialRemark,MaterialDefDate,MaterialValidStar,MaterialValidEnd,ReceiverPeoplNum,MaterialStatus,AlreadySubmitNum,FieldNum,CreatePeopleCode,CreateDate ");
			strSql.Append(" FROM oa_material_definition ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "oa_material_definition";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

